package cn.com.servletcontext;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "sContext02", value = "/sContext02")
public class sContext02 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取ServletContext对象，该对象包含了Web应用程序的上下文信息
        ServletContext context = this.getServletContext();

        //定义应用级范围的数据，用于共享
        context.setAttribute("data", "应用范围的数据");

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}